package com.xmy.cultivate.mapper;

import com.xmy.cultivate.entity.CourseSchedulingAlways;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;

/**
 * <p>
 * 日期总排课表，计算缺课使用(校历) Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2024-03-20
 */
public interface CourseSchedulingAlwaysMapper extends BaseMapper<CourseSchedulingAlways> {

    @Select("select * from course_scheduling_always where year_part = ${yearPart} and quarter_num =${quarterNum} and grade_section =${gradeSection} and '${dateNow}' BETWEEN start_date and end_date LIMIT 1")
    public CourseSchedulingAlways getOneForYearAndDate(@Param("yearPart") Integer yearPart,@Param("quarterNum") Integer quarterNum,@Param("gradeSection") Integer gradeSection,@Param("dateNow") String dateNow);

    @Select("select MAX(end_date) as max_end_date from course_scheduling_always where year_part = ${yearPart} and quarter_num =${quarterNum} and grade_section =${gradeSection} LIMIT 1")
    public LocalDate getMaxEndDate(@Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("gradeSection") Integer gradeSection);


    /**
     * 根据日期获取课次
     * @param nowDate
     * @param gradeSection
     * @return
     */
    @Select("select * from course_scheduling_always where grade_section = ${gradeSection} and #{nowDate} BETWEEN start_date and end_date and deleted =0 LIMIT 1")
    CourseSchedulingAlways getOneForDate(@Param("nowDate") LocalDate nowDate,@Param("gradeSection") Integer gradeSection);

    @Select("select * from course_scheduling_always where year_part = ${yearPart} and quarter_num = ${quarterNum} and num = ${num} and grade_section =${gradeSection} and deleted = 0  limit 1")
    public CourseSchedulingAlways getOneForNum(@Param("yearPart")Integer yearPart,@Param("quarterNum")Integer quarterNum,@Param("num") Integer num, @Param("gradeSection") Integer gradeSection);

}
